<?php
// +----------------------------------------------------------------------
// | ThinkBLOG (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | @link ( http://www.yurnero.net )
// +----------------------------------------------------------------------
// | @licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | @author nicholas <nicholasinlove@126.com>
// +----------------------------------------------------------------------
// | $Id: WapCheckBehavior.class.php 105 2012-04-06 07:47:44Z nicholasinlove1986@gmail.com $
// +----------------------------------------------------------------------


class WapCheckBehavior extends Behavior {
	
	protected $options = array ('WAP_REDIRECT_ON' => false );
	
	public function run(&$params) {
		$Loaction = 'm/';
		if (C ( 'WAP_REDIRECT_ON' ) && self::isWap ()) {
			header ( "Location: $Loaction\n" );
			exit ();
		}
	}
	
	static private function isWap() {
		$ua = strtolower ( $_SERVER ['HTTP_USER_AGENT'] );
		$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";
		if (($ua == '' || preg_match ( $uachar, $ua )) && ! strpos ( strtolower ( $_SERVER ['REQUEST_URI'] ), 'wap' )) {
			return true;
		} else {
			return false;
		}
	}
	
}